package com.cgsd.heyu.widgets;


import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

/**
 * @author xiaoxing
 * Created by pengsheng-2 on 2018/8/23.
 * 比例image
 */

public class ScaleImageView extends RelativeLayout {

    public ScaleImageView(Context context) {
        this(context, null);
    }

    public ScaleImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ScaleImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // 宽模式
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        // 宽大小
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        // 高大小
        int heightSize;
        // 只有宽的值是精确的才对高做精确的比例校对
//        if (widthMode == MeasureSpec.EXACTLY && mRatio > 0) {
//            heightSize = (int) (widthSize / mRatio + 0.5f);
//            heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize,
//                    MeasureSpec.EXACTLY);
//        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}
